<template>
  <view class="container">
    <view class="form-wrapper">
      <u--form
        labelPosition="left"
        :model="form"
        :rules="rules"
        ref="dataForm"
        label-width="120"
      >
        <view class="form-section">
          <view class="section-title">
            <u-icon name="grid" color="#4A90E2" size="32"></u-icon>
            <text class="section-text">基本信息</text>
          </view>
          <!-- <u-form-item label="邀请码" prop="parent_id" :borderBottom="false">
            <view style="margin: 10rpx 0" v-show="state.tgcompany_name">
              {{ state.tgcompany_name }}</view
            >
            <u--input
              v-if="!state.tgcompany_name"
              v-model="form.parent_id"
              placeholder="请输入邀请码"
              
              placeholderClass="placeholder-style"
              inputClass="input-style"
              @blur="handleBlur"
              :disabled="state.tg"
            ></u--input>
          </u-form-item> -->
          <u-form-item
            label="邀请码"
            prop="parent_id"
            :borderBottom="false"
            v-if="state.ZhanShiMa"
          >
            <view
              style="margin: 10rpx 0"
              v-if="state.tgcompany_name"
              v-show="state.tgcompany_name"
              >姓名：{{ state.tgcompany_name }}</view
            >
            <u--input
              v-if="!state.tgcompany_name"
              v-model="form.parent_id"
              placeholder="请输入邀请码"
              placeholderClass="placeholder-style"
              inputClass="input-style"
              @blur="handleBlur"
              :disabled="state.tg"
            ></u--input>
            <view v-if="state.tgcompany_name" style="margin-left: 10px">
              邀请码：{{ state.share_code }}
            </view>
          </u-form-item>
          <u-form-item prop="company_name" :borderBottom="false">
            <view class="xingX">
              <text class="xing">*</text>
              <text>公司名称</text>
            </view>
            <u--input
              v-model="form.company_name"
              placeholder="请输入公司全称"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            label="队伍名称:"
            prop="team_name"
            :borderBottom="false"
            v-if="[6].includes(Number(form.company_type))"
          >
            <u--input
              v-model="form.team_name"
              placeholder="请输入公司全称"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            label="公司类型"
            prop="company_type"
            :borderBottom="false"
          >
            当前注册类型：{{ state.company_type[form.company_type - 1] }}
            <!-- <view @click="state.PickerShow = true">
              {{ state.PickerTitle ? state.PickerTitle : "选择公司类型" }}
            </view>
            <u-picker
              :show="state.PickerShow"
              :columns="[state.company_type]"
              @cancel="state.PickerShow = false"
              @confirm="ClickConfirm"
            ></u-picker> -->
          </u-form-item>

          <u-form-item
            label="主营业务:"
            prop="main_ye_wu"
            :borderBottom="false"
            v-if="[2, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
          >
            <u--input
              v-model="form.main_ye_wu"
              placeholder="请输入公司全称"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7].includes(Number(form.company_type))"
            label="经营开始时间"
            prop="run_date"
            :borderBottom="false"
          >
            <view @click="state.runDatePickerShow = true">
              {{ form.run_date ? form.run_date : "请选择选择日期" }}
            </view>
            <!-- <u--input
              v-model="form.run_date"
              placeholder="请输入经营开始时间"
              
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input> -->
            <u-datetime-picker
              :show="state.runDatePickerShow"
              v-model="form.run_date"
              :formatter="formatter"
              mode="date"
              @confirm="runDatePickerConfirm"
              @cancel="state.runDatePickerShow = false"
            ></u-datetime-picker>
          </u-form-item>
          <u-form-item
            v-if="[8].includes(Number(form.company_type))"
            label="成立日期"
            prop="register_date"
            :borderBottom="false"
          >
            <view @click="state.validPickerShow = true">
              {{ form.register_date ? form.register_date : "请选择选择日期" }}
            </view>
            <u-datetime-picker
              :show="state.validPickerShow"
              v-model="form.register_date"
              :formatter="formatter"
              mode="date"
              @confirm="validPickerConfirm"
              @cancel="state.validPickerShow = false"
            ></u-datetime-picker>
          </u-form-item>
          <u-form-item
            v-if="[8].includes(Number(form.company_type))"
            label="主管单位"
            prop="zhu_guan_company"
            :borderBottom="false"
          >
            <u--input
              v-model="form.zhu_guan_company"
              placeholder="请输入主管单位"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            />
          </u-form-item>
          <u-form-item
            v-if="[8].includes(Number(form.company_type))"
            label="会员单位数量"
            prop="user_num"
            :borderBottom="false"
          >
            <u--input
              v-model="form.user_num"
              placeholder="请输入会员单位数量"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            />
          </u-form-item>
          <u-form-item
            v-if="[7].includes(Number(form.company_type))"
            label="主要客户"
            prop="main_customer"
            :borderBottom="false"
          >
            <u--textarea
              v-model="form.main_customer"
              placeholder="请输入主要客户名称，多个用逗号分隔"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            />
          </u-form-item>

          <u-form-item
            v-if="[3].includes(Number(form.company_type))"
            label="生产商品"
            prop="make_goods"
            :borderBottom="false"
          >
            <u--input
              v-model="form.make_goods"
              placeholder="请输入生产商品"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[3, 7].includes(Number(form.company_type))"
            label="经销商品"
            prop="sale_goods"
            :borderBottom="false"
          >
            <u--input
              v-model="form.sale_goods"
              placeholder="请输入经销商品"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="负责人姓名"
            prop="person_realname"
            :borderBottom="false"
          >
            <u--input
              v-model="form.person_realname"
              placeholder="请输入负责人姓名"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="负责人职务"
            prop="person_duty"
            :borderBottom="false"
          >
            <u--input
              v-model="form.person_duty"
              placeholder="请输入负责人职务"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>

          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="负责人手机号"
            prop="person_mobile"
            :borderBottom="false"
          >
            <u--input
              v-model="form.person_mobile"
              placeholder="请输入负责人手机号"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>

          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="联系人姓名"
            prop="linkman_realname"
            :borderBottom="false"
          >
            <u--input
              v-model="form.linkman_realname"
              placeholder="请输入联系人姓名"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="联系人职务"
            prop="linkman_duty"
            :borderBottom="false"
          >
            <u--input
              v-model="form.linkman_duty"
              placeholder="请输入联系人职务"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            />
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="联系人手机号"
            prop="linkman_mobile"
            :borderBottom="false"
          >
            <u--input
              v-model="form.linkman_mobile"
              placeholder="请输入联系人手机号码"
              placeholderClass="placeholder-style"
              inputClass="input-style"
              type="number"
            ></u--input>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="联系人邮箱"
            prop="linkman_email"
            :borderBottom="false"
          >
            <u--input
              v-model="form.linkman_email"
              placeholder="请输入联系人邮箱"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <!-- 选择地址（非必填，无*，保持不变） -->
          <!-- <u-form-item
            v-if="
              ['2', '3', '4', '5', '6', '7', '8'].includes(form.company_type)
            "
            label="选择地址"
            :borderBottom="false"
          >
            <view
              @click="choseaddress"
              style="
                padding: 10px;
                border: 1px solid #dadbde;
                border-radius: 5px;
                color: #606266;
                width: 80%;
              "
            >
              {{ state.weizhi ? state.weizhi : "请选择地理位置" }}
            </view>
          </u-form-item> -->
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="所在地区"
            prop="city_code"
            :borderBottom="false"
          >
            <u-area-picker
              v-model="form.city_code"
              closeOnClickOverlay
              showInput
              placeholder="请选择省市区"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u-area-picker>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="详细地址"
            prop="city_address"
            :borderBottom="false"
          >
            <u--input
              v-model="form.city_address"
              placeholder="请输入街道门牌号等详细信息"
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input>
          </u-form-item>
          <u-form-item
            label="三大电网"
            prop="dian_id"
            :borderBottom="false"
            v-if="[2, 3, 4, 5, 6].includes(Number(form.company_type))"
          >
            <u-checkbox-group
              v-model="form.dian_id"
              placement="row"
              @change="checkbox"
            >
              <div
                :style="{
                  display: 'grid',
                  gap: ' 8px 16px',
                  ' align-items': 'center',
                  'grid-template-columns': `repeat(2, 1fr)`,
                }"
              >
                <u-checkbox
                  v-for="(item, index) in state.GetIndexDian"
                  :key="index"
                  :customStyle="{ marginBottom: '8px', marginTop: '5px' }"
                  :label="item.name"
                  :name="item.id"
                  :disabled="item.disabled"
                  :checked="item.checked"
                />
              </div>
            </u-checkbox-group>
            <!-- <u--input
              v-model="form.dian_id"
              placeholder="请输入三大电网"
              
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input> -->
          </u-form-item>
          <u-form-item
            label="五大六小"
            prop="ji_tuan_id"
            :borderBottom="false"
            v-if="[2, 3, 4, 5, 6].includes(Number(form.company_type))"
          >
            <!-- <u--input
              v-model="form.ji_tuan_id"
              placeholder="请输入五大六小"
              
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input> -->
            <u-checkbox-group
              v-model="form.ji_tuan_id"
              placement="row"
              @change="checkbox"
            >
              <div
                :style="{
                  display: 'grid',
                  gap: ' 8px 16px',
                  ' align-items': 'center',
                  'grid-template-columns': `repeat(1, 1fr)`,
                }"
              >
                <u-checkbox
                  v-for="(item, index) in state.GetIndexJiTuan"
                  :key="index"
                  :customStyle="{ marginBottom: '8px', marginTop: '5px' }"
                  :label="item.name"
                  :name="item.id"
                  :disabled="item.disabled"
                  :checked="item.checked"
                />
              </div>
            </u-checkbox-group>
          </u-form-item>
          <u-form-item
            label="外贸"
            prop="wai_mao_id"
            :borderBottom="false"
            v-if="form.company_type != '8'"
          >
            <u-checkbox-group
              v-model="form.wai_mao_id"
              placement="row"
              @change="checkbox"
            >
              <u-checkbox
                v-for="(item, index) in state.GetIndexWaiMao"
                :key="index"
                :customStyle="{ marginBottom: '8px', marginTop: '5px' }"
                :label="item.name"
                :name="item.id"
                :disabled="item.disabled"
                :checked="item.checked"
              />
            </u-checkbox-group>
            <!-- <u--input
              v-model="form.wai_mao_id"
              placeholder="请输入外贸"
              
              placeholderClass="placeholder-style"
              inputClass="input-style"
            ></u--input> -->
          </u-form-item>
          <u-form-item
            v-if="[2, 4, 5, 6].includes(Number(form.company_type))"
            label="拥有资质"
            prop="zi_zhi"
            :borderBottom="false"
          >
            <view class="upload-tips" v-if="form.zi_zhi.length == 0">
              <text>请上传清晰拥有资质:</text>
            </view>
            <u-upload
              :fileList="form.zi_zhi"
              @afterRead="onChooseAvatarZiZhi"
              @delete="handleDeleteZiZhi"
              name="unlimitedUpload"
              multiple
              :maxCount="5"
              accept="image"
            >
              <template #default>
                <view
                  v-if="form.zi_zhi.length != 5"
                  style="
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;
                  "
                >
                  <u-icon name="plus" size="40"></u-icon>
                  <text>点击上传</text>
                </view>
              </template>
            </u-upload>
          </u-form-item>
          <u-form-item
            v-if="[2, 3, 4, 5, 6, 7, 8].includes(Number(form.company_type))"
            label="营业执照"
            prop="company_license"
            :borderBottom="false"
          >
            <view class="upload-tips" v-if="form.company_license.length == 0">
              <text>请上传清晰营业执照:</text>
            </view>
            <u-upload
              :fileList="form.company_license"
              @afterRead="onChooseAvatar"
              @delete="handleDelete"
              name="unlimitedUpload"
              multiple
              :maxCount="Infinity"
              accept="image"
            >
              <template #default>
                <view
                  v-if="form.company_license.length == 0"
                  style="
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;
                  "
                >
                  <u-icon name="plus" size="40"></u-icon>
                  <text>点击上传</text>
                </view>
              </template>
            </u-upload>
          </u-form-item>
        </view>
        <view style="width: 80vw; margin: 40rpx auto">
          <u-button
            type="primary"
            text="确定提交"
            @click="submitForm"
          ></u-button>
          <view style="margin: 10rpx 0"></view>
          <u-button type="success" text="返回首页" @click="fc"></u-button>
        </view>
      </u--form>
    </view>
  </view>
</template>

<script setup>
import { ref, reactive, toRefs, watch } from "vue";
import { showToast, showLoading, hideLoading } from "@/utils/toast";
import { formatDate } from "@/utils/date.js";
import {
  GetUserCompany,
  PostUserCompany,
  GetIndexDian,
  GetIndexJiTuan,
  GetIndexWaiMao,
  readByShareCode,
} from "@/api/userInfo.js";
import { onLoad } from "@dcloudio/uni-app";
const state = reactive({
  ZhanShiMa: true,
  weizhi: "",
  validPickerShow: false,
  PickerShow: false,
  PickerTitle: "",
  tg: false,
  tgcompany_name: "",
  share_code: "",
  GetIndexDian: [],
  GetIndexJiTuan: [],
  GetIndexWaiMao: [],
  company_type: [
    "居间人",
    "工程公司",
    "物资工厂",
    "设计公司",
    "监理公司",
    "劳务公司",
    "物资贸易商",
    "行业协会",
  ],
  form: {
    id: "",
    parent_id: "",
    // 公司类型 1=居间人,2=工程公司,3=物资工厂,4=设计公司,5=监理公司,6=劳务公司,7=物资贸易商,8=电力协会
    company_type: "",
    // 公司名称（必填）
    company_name: "",
    team_name: "", //队伍名称
    zi_zhi: [],
    // 营业执照编号（图片上传后返回的ID）
    company_license: [],
    main_ye_wu: "", //主营业务
    // 经营开始时间（日期字符串，格式：YYYY-MM-DD）
    run_date: "",
    // 成立日期（日期字符串，格式：YYYY-MM-DD）
    register_date: "",
    // 主管单位（选填）
    zhu_guan_company: "",
    // 会员单位数量（数字）
    user_num: "",
    // 主要客户（多个用逗号分隔）
    main_customer: "",
    // 生产商品（选填）
    make_goods: "",
    // 经销商品（选填）
    sale_goods: "",
    // 负责人姓名（必填）
    person_realname: "",
    // 负责人职务（选填）
    person_duty: "",
    // 负责人手机号（必填，需验证格式）
    person_mobile: "",
    // 联系人姓名（必填）
    linkman_realname: "",
    // 联系人职务（选填）
    linkman_duty: "",
    // 联系人手机号（必填，需验证格式）
    linkman_mobile: "",
    // 联系人邮箱（选填，需验证格式）
    linkman_email: "",
    // 所在地区（省市区编码数组）
    city_code: [],
    // 详细地址（街道门牌号等）
    city_address: "",
    // 经度（地图定位后自动填充）
    // city_long: "",
    // // 纬度（地图定位后自动填充）
    // city_lat: "",
    // 三大电网关联ID（选填）
    dian_id: "",
    // 五大六小集团关联ID（选填）
    ji_tuan_id: "",
    // 外贸标识（选填）
    wai_mao_id: "",
    // 推广人ID（0表示无推广人）
    parent_id: "",
  },
  rules: {
    company_name: [
      { required: true, message: "请输入公司名称", trigger: "blur" },
    ],
    main_ye_wu: [
      { required: true, message: "请输入公司类型", trigger: "change" },
    ],
    person_mobile: [
      { required: true, message: "请输入负责人手机号", trigger: "blur" },
    ],
    linkman_mobile: [
      { required: true, message: "请输入联系人手机号", trigger: "blur" },
    ],
    linkman_email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
    // city_code: [
    //   { required: true, message: "请选择所在地区", trigger: "change" },
    // ],
    city_address: [
      { required: true, message: "请输入详细地址", trigger: "blur" },
    ],
  },
});

const { form, rules } = toRefs(state);
const dataForm = ref(null);

onLoad(async (e) => {
  // console.log();
  // console.log(e.company_type);
  form.value.company_type = e.company_type;
  if (e.id) {
    state.ZhanShiMa = false;
    form.value.id = e.id;
  }
  await init();
});

const init = async () => {
  if (form.value.id) {
    try {
      const res = await GetUserCompany();
      form.value = res.data;
    } catch (error) {}
  }
  try {
    const res = await GetIndexDian();
    state.GetIndexDian = res.data;
  } catch (error) {}
  try {
    const res = await GetIndexJiTuan();
    state.GetIndexJiTuan = res.data;
  } catch (error) {}

  try {
    const res = await GetIndexWaiMao();
    state.GetIndexWaiMao = res.data;
  } catch (error) {}
};
const handleBlur = async () => {
  if (form.value.parent_id > 0) {
    try {
      const res = await readByShareCode(form.value.parent_id);
      console.log(res);
      if (res.code == 10000) {
        state.tgcompany_name = res.data.company_name;
        state.share_code = res.data.share_code;
        form.value.parent_id = res.data.id;
        state.tg = true;
      } else {
        state.tg = false;
      }
    } catch (error) {}
  }
};
// 提交表单
const submitForm = async () => {
  // if (form.value.need_city_code) {
  //   showToast("请选择项目地点");
  // }
  dataForm.value
    .validate()
    .then(async (valid) => {
      if (valid) {
        console.log("表单验证通过:", form.value);
        try {
          showLoading("提交中...");
          const res = await PostUserCompany(state.form);
          hideLoading();
          if (res.code == 10000) {
            showToast("提交成功");
            setTimeout(() => {
              uni.redirectTo({
                url: "/pages/index/index",
              });
            }, 500);
            // goBack();
          } else {
            showToast(res.message || "提交失败，请重试");
          }
        } catch (error) {
          hideLoading();
          showToast("网络错误，请重试");
          console.error("提交错误:", error);
        }
      } else {
        showToast("请检查表单是否填写完整");
      }
    })
    .catch(() => {
      showToast("请检查表单是否填写完整");
    });
};
const fc = () => {
  // 返回首页逻辑
  uni.navigateBack();
};
const ClickConfirm = (e) => {
  // console.log(e.value[0]);
  form.value.company_type = e.value[0].value;
  state.PickerTitle = e.value[0].text;
  state.PickerShow = false;
};
// 信息有效期选择器确认
const validPickerConfirm = (e) => {
  form.value.register_date = formatDate(new Date(e.value), "YYYY-MM-DD");
  state.validPickerShow = false;
};
const runDatePickerConfirm = (e) => {
  form.value.run_date = formatDate(new Date(e.value), "YYYY-MM-DD");
  state.runDatePickerShow = false;
};
const formatter = (type, value) => {
  if (type === "year") {
    return `${value}年`;
  }
  if (type === "month") {
    return `${value}月`;
  }
  if (type === "day") {
    return `${value}日`;
  }
  return value;
};

// const choseaddress = async () => {
//   console.log(123);
//   try {
//     const res = await uni.chooseLocation();
//     console.log("位置名称：" + res.name);
//     state.weizhi = res.name;
//     console.log("详细地址：" + res.address);
//     form.value.city_lat = res.latitude;
//     form.value.city_long = res.longitude;
//   } catch (error) {
//     showToast("选择位置失败");
//     console.error("选择位置失败:", error);
//   }
// };
// const choseaddress = () => {
//   uni.chooseLocation({
//     success: function (res) {
//       console.log("位置名称：" + res.name);
//       let { lng, lat } = that.qqMapTransBMap(res.longitude, res.latitude);
//       // that.dingwei.lname = res.name
//       // that.dingwei.xxaddress = res.address
//       // that.dingwei.latitude = lat
//       // that.dingwei.longitude = lng
//       // that.weizhi = res.name;
//       state.weizhi = res.name;
//       console.log("详细地址：" + res.address);

//       form.value.city_lat = res.latitude;
//       form.value.city_long = res.longitude;
//     },
//   });
// };

const onChooseAvatar = async (e) => {
  try {
    const newFiles = e.file;

    const listUrl = await uploadFilePromise(newFiles[0].url);

    form.value.company_license = [
      {
        url: listUrl.web_url,
        web_url: listUrl.url,
      },
    ];
  } catch (err) {
    showToast("获取图片失败，请重试");
  }
};
const handleDelete = (event) => {
  form.value.company_license.splice(event.index, 1);
};

const onChooseAvatarZiZhi = async (e) => {
  try {
    const newFiles = e.file;

    const listUrl = await uploadFilePromiseZiZhi(newFiles[0].url);

    form.value.zi_zhi = [
      ...form.value.zi_zhi,
      {
        url: listUrl.web_url,
        web_url: listUrl.url,
      },
    ];
  } catch (err) {
    showToast("获取图片失败，请重试");
  }
};
const handleDeleteZiZhi = (event) => {
  form.value.zi_zhi.splice(event.index, 1);
};

// 上传文件到服务器
const uploadFilePromise = (filePath) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${import.meta.env.VITE_API_URL}/upload/image`,
      filePath: filePath,
      name: "file",
      header: {
        Authorization: "Bearer " + uni.getStorageSync("token"),
        "content-type": "multipart/form-data; charset=utf-8",
      },
      formData: {
        type: "avatar",
      },
      success: (res) => {
        const data = JSON.parse(res.data);
        if (data.code == 10000 && data.data?.url) {
          resolve(data.data);
        } else {
          reject(new Error(data.msg || "上传失败"));
        }
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
// 上传文件到服务器
const uploadFilePromiseZiZhi = (filePath) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${import.meta.env.VITE_API_URL}/upload/image`,
      filePath: filePath,
      name: "file",
      header: {
        Authorization: "Bearer " + uni.getStorageSync("token"),
        "content-type": "multipart/form-data; charset=utf-8",
      },
      formData: {
        type: "avatar",
        file_type: "6",
      },
      success: (res) => {
        const data = JSON.parse(res.data);
        if (data.code == 10000 && data.data?.url) {
          resolve(data.data);
        } else {
          reject(new Error(data.msg || "上传失败"));
        }
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
</script>
<style lang="scss" scoped>
.xingX {
  width: 200rpx;
  display: flex;
  align-content: center;
}
.xing {
  color: red;
  margin-right: 4rpx;
}

form-container {
  min-height: 100vh;
  background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
  padding-bottom: 40rpx;
}

.header {
  background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
  padding: 100rpx 40rpx 40rpx;
  text-align: center;
  color: white;

  .header-title {
    display: block;
    font-size: 40rpx;
    font-weight: bold;
    margin-bottom: 16rpx;
  }

  .header-subtitle {
    font-size: 26rpx;
    opacity: 0.9;
    line-height: 1.4;
  }
}

.form-wrapper {
  margin: 0 30rpx;
  background: white;
  border-radius: 24rpx;
  padding: 40rpx 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
}

.form-section {
  margin-bottom: 40rpx;

  &:last-child {
    margin-bottom: 0;
  }
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  padding: 0 10rpx;

  .section-text {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-left: 16rpx;
  }
}

.submit-section {
  margin-top: 60rpx;
  text-align: center;

  .tip-text {
    display: block;
    color: #999;
    font-size: 24rpx;
    margin-top: 20rpx;
  }
}

// 输入框样式优化
:deep(.u-input) {
  font-size: 28rpx !important;
  color: #333 !important;
}

// 占位符样式
:deep(.u-input__input) {
  color: #333 !important;

  &::placeholder {
    color: #999 !important;
  }
}
</style>
